from django.db import models
from django.conf import settings

# Create your models here.
class BackendUser(models.Model):
    username = models.CharField(max_length=10, blank=False, null=False)
    password = models.CharField(max_length=10, blank=False, null=False)

    class Meta:
        db_table = "backend_user"
        verbose_name = '表'
        verbose_name_plural = verbose_name
        # ordering = ('sort',)

class Student(models.Model):
    # 模型字段
    name = models.CharField(max_length=100,verbose_name="姓名",help_text='提示文本：不能为空')
    sex = models.BooleanField(default=1,verbose_name="性别")
    age = models.IntegerField(verbose_name="年龄")
    class_null = models.CharField(max_length=5,verbose_name="班级编号")
    description = models.TextField(max_length=1000,verbose_name="个性签名")

    #通过django migrate默认创建的表名是 应用名_类名小写，如果不想用默认的，可以自己配置表的元信息
    #通过class Meta类来配置
    class Meta:
        #配置表名
        db_table="tb_student"
        #这里是为了配置Django的后台管理系统admin里面的表名
        verbose_name = "学生"
        #这里是为了配置让表名不以复数形式显示，默认是以复数形式显示
        verbose_name_plural = verbose_name


class Course(models.Model):
    name = models.CharField(max_length=255, unique=True, help_text='课程名称', verbose_name='名称')
    introduction = models.TextField(help_text='课程介绍', verbose_name='介绍')
    teacher = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, help_text='课程讲师',
                                verbose_name='讲师')
    price = models.DecimalField(max_digits=6, decimal_places=2, help_text='课程价格')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        verbose_name = "课程信息"
        verbose_name_plural = verbose_name
        ordering = ('price',)

    def __str__(self):
        return self.name

